import  random
import string
'''
a = {
    "666666":{"账号":"666666","密码":"123456","姓名":"张三","余额":"10"},
    "000001":{"账号":"000001","密码":"123456","姓名":"李四","余额":"20"}
}
'''
a={}
#添加判断
def adduser(test1): # test1  账号值
    if len(a) < 100:
        if test1 in a:
            return 2
        else:
            # 存数据
            return 1
    else:
        return 3

#存钱查询判断
def inquire(test2):
    if test2 in a:
        return True
    else:
        return False
#取钱查询判断
def inquire2(test3,test4,test5):
    if test3 in a:
        for i in a:
            if test3 == a[i]['账号']:
                if test4 == int(a[i]['密码']):
                    if int(test5) > int(a[i]['余额']):
                        return 3
                    else:
                        return 4
                else:
                    return 2
    else:
        return 1
#转账查询的判断
def inquire3(test1,test2,test3,test4):
    if test1 and test2 in a:
        for i in a:
            if test2== a[i]['账号']:
                if test3 == int(a[i]['密码']):
                    if int(test4) > int(a[i]['余额']):
                        return 3
                    else:
                        return 4
                else:
                    return 2
    else:
        return 1
#查询的判断
def inquire4(test1,test2):
    if test1 in a:
        for i in a:
            if test1 == a[i]['账号']:
                if test2 == int(a[i]['密码']):
                    return 3
                else:
                    return 2
    else:
        return 1



while True :
    print("************************")
    print("*      中国工商银行       *")
    print("*      账户管理系统       *")
    print("*         v1.0         *")
    print("************************")
    print("*1.0 开户               *")
    print("*2.0 存钱               *")
    print("*3.0 取钱               *")
    print("*4.0 转账               *")
    print("*5.0 查询               *")
    print("*6.0 bye！              *")
    print("************************")

    user = int(input("请选择需要办理的业务:"))

    if user <1 or user >6:
        print("输入错误！")
        continue


    # 添加用户
    if user == 1:
        num = ''.join(random.sample(string.digits, 8))
        name = str(input("请输入您的姓名:"))
        key = int(input("请输入您的6位数密码:"))
        while len(str(key)) != 6:
            print("请输入正确的密码")
            key = int(input("请输入您的6位数密码:"))
        place = []
        country = str(input("请输入您的国籍:"))
        province = str(input("请输入您的省份:"))
        street = str(input("请输入您的街道:"))
        house = str(input("请输入您的门派号:"))
        money = int(input("请输入您的存款余额:"))
        place.append(country)
        place.append(province)
        place.append(street)
        place.append(house)
        bank = str(input("请输入您的开户行:"))
        test = adduser(num)

        if test == 1:
            a[num] = {
                '账号' :num,
                '姓名':name,
                '密码':key,
                '地址':place,
                '余额':money,
                '开户行':bank
            }
            print("开户成功")
            print("您的账号为:",num)
            print("您的密码为:",key)
        elif test == 2:
            print("用户已存在")
        elif test == 3:
            print("用户库已满")
        continue

    #存钱
    if user == 2:
        usernum = input("请输入您的账号：")
        move_money = int(input("请输入存入金额:"))
        test1 = inquire(usernum)
        if test1 == True:
            for i in a:
                if usernum == a[i]['账号']:
                    a[i]['余额']= int(a[i]['余额'])+move_money
                    print(a)
                    continue
        else:
            print("您输入的账号不存在！")
            continue

    #取钱
    if user == 3:
        usernum = input("请输入您的账号:")
        userkey = int(input("请输入您的密码:"))
        move_money = int(input("请输入取钱金额:"))
        test = inquire2(usernum,userkey,move_money)
        if test == 1:
            print("您输入的账号不存在！")
        elif test == 2:
            print("您输入的密码错误！")
        elif test == 3:
            print("您取出的金额大于您的余额！")
        elif test == 4:
            for i in a:
                if usernum == a[i]['账号']:
                    a[i]['余额'] = int(a[i]['余额']) - move_money
        continue
    #转账
    if user == 4:
        innum = input("请输入转入的账号:")
        outnum = input("请输入转出的账号:")
        outkey = int(input("请输入转出账号的密码:"))
        move_money = int(input("请输入转出的金额:"))
        test = inquire3(innum, outnum,outkey, move_money)
        if test == 1:
            print("您输入的账号不存在！")
        elif test == 2:
            print("您输入的密码错误！")
        elif test == 3:
            print("您取出的金额大于您的余额！")
        elif test == 4:
            for i in a:
                if outnum == a[i]['账号']:
                    a[i]['余额'] = int(a[i]['余额']) - move_money
                if innum == a[i]['账号']:
                    a[i]['余额'] = int(a[i]['余额']) + move_money
        continue
    #查询
    if user == 5:
        usernum = input("请输入要查询的账号:")
        userkey = int(input("请输入要查询账号的密码:"))
        test = inquire4(usernum,userkey)
        if test == 1:
            print("该用户不存在")
        elif test == 2:
            print("您输入的密码不正确")
        elif test == 3:
            for i in a:
                if usernum == a[i]['账号']:
                    print(a[i])
        continue


    if user == 6:
        print("再见")
        break